<?php
/*
write by vomtung@yahoo.com.vn
use to serch user, reference file class User_AdminManageController extends Core_Controller_Action_Admin
*/
 class Mobileservice_SocialEngineStatisticsController extends Core_Controller_Action_Standard
{
  public function indexAction()
  {
  
	$this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender();
  }
  public function todaystatisticsAction()
  {
	$this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender();
	 
	echo json_encode(array(
	'pageviews' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('core.views', 'day'),
	'members' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('user.creations', 'day'),
	'signins' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('user.logins', 'day'),
	'privatemessages' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('messages.creations', 'day'),
	'friendships' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('user.friendships', 'day'),
	'comments' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('core.comments', 'day'),
	'abusereports' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('core.reports', 'day'),
	'announcements' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('announcement.creations', 'day'),
	'emailssent' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('core.emails', 'day'),
	));
  }
  public function totalstatisticsAction()
  {
  
	$this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender();
	 // Online users
    $onlineTable = Engine_Api::_()->getDbtable('online', 'user');
    $onlineUserCount = $onlineTable->select()
      ->from($onlineTable->info('name'), new Zend_Db_Expr('COUNT(DISTINCT user_id)'))
      ->where('user_id > ?', 0)
      ->where('active > ?', new Zend_Db_Expr('DATE_SUB(NOW(),INTERVAL 20 MINUTE)'))
      ->query()
      ->fetchColumn(0)
      ;
	echo json_encode(array(
	'pageviews' =>Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('core.views'),
	'members' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('user.creations'),
	'signins' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('user.logins'),
	'privatemessages' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('messages.creations'),
	'friendships' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('user.friendships'),
	'comments' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('core.comments'),
	'abusereports' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('core.reports'),
	'announcements' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('announcement.creations'),
	'emailssent' => Engine_Api::_()->getDbtable('statistics', 'core')->getTotal('core.emails'),
	'onlinemembers' => $onlineUserCount
	));
  }
}
 ?>